import java.util.concurrent.CountDownLatch;

public class Demo32 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for(int i = 0; i < 10; i++)
        {
            int id = i;
            Thread t = new Thread(() -> {
                System.out.println("thread " + id);
                try {
                    Thread.sleep(500);
                }catch (InterruptedException e)
                {
                    throw new RuntimeException(e);
                }

                countDownLatch.countDown();
            });
            t.start();
        }

        countDownLatch.await();
        System.out.println("所有任务都完成");
    }
}
